﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawner : MonoBehaviour {

    public static int CountEnemyAlive = 0;
    public Wav[] waves;
    public Transform start;
    public float waveRate = 3;

    void Start()
    {
        StartCoroutine(SpawnEnemy());
    }

    IEnumerator SpawnEnemy()
    {
        foreach (Wav wav in waves)
        {
            for (int i = 0; i < wav.count; i++)
            {
                Instantiate(wav.enemyPrefab, start.position, Quaternion.identity);
                CountEnemyAlive++;
                if (i != wav.count -1)
                    yield return new WaitForSeconds(wav.rate);
            }
            while (CountEnemyAlive > 0)
            {
                yield return 0;
            }
            yield return new WaitForSeconds(waveRate);
        }
    }
}
